package com.swh.controller.business;

import com.github.pagehelper.PageInfo;
import com.swh.entity.Demand;
import com.swh.service.DemandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/14 14:41
 * @Version: 1.0
 */
@Controller
@RequestMapping("/guguanjia/demand")
public class DemandController {

    @Autowired
    private DemandService demandService;

    @RequestMapping("/index")
    public String login() {
        return "/demand/index";
    }

    @RequestMapping("/findAll/{pageNum}/{pageSize}")
    @ResponseBody
    public PageInfo<Demand> findAll(@PathVariable("pageNum")int pageNum , @PathVariable("pageSize") int pageSize) {
        return demandService.findPage(pageNum,pageSize);
    }

    @RequestMapping("/toUpdate")
    public String tuUpdate() {
        return  "/demand/detail";
    }

    @RequestMapping("/toUpdate2")
    public String tuUpdate2() {
        return  "/demand/update";
    }

    @ResponseBody
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public void updateById(@RequestBody Demand demand){
        demandService.update(demand);
    }



    //根据id查询并且回写数据
    @ResponseBody
    @RequestMapping("/get")
    public Object get(Integer id){
        Demand demand = demandService.findById(id);
        return demand;
    }


}
